/**
 *
 */
package com.nightwalker.xsite.dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;

import com.nightwalker.xsite.infra.ServiceLocator;

/**
 * Dao
 * <br><br>
 * <b>Description:</b> Classe base de daos. Contem os metodos comuns a todos os daos.
 * <br><br>
 * Created in Jan 27, 2008 6:31:33 PM
 * <br>
 * <b>version:</b> 1.0
 * <br>
 * <b>Modifications:</b>
 */
public abstract class Dao {
	protected static Logger log = Logger.getLogger(Dao.class);

	public Dao(){
		ServiceLocator serviceLocator = new ServiceLocator();
		conexao = serviceLocator.getConnection();
	}

	protected Connection conexao;

	public boolean closeConnection(){
		log.debug("Fechando a conexão");
		try {
			conexao.close();
			log.debug("Conexão fechada com sucesso");
			return true;
		} catch (SQLException e) {
			log.error("Erro ao fechar a conexão", e);
		}
		return false;
	}

	public Date formatarData(String data, String pattern) throws ParseException{
		log.debug("Formatando data");
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);

		return simpleDateFormat.parse(data);
	}

	public String formatarData(Date data, String pattern){
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
		return simpleDateFormat.format(data);

	}



}
